/*
 * Copyright (C) 2011-2012 5ifilm.net. All Rights Reserved.
 * $Id: InitialCacheServlet.java 2012-08-02 wangjun@gmail.com$
 *
 */
package net.ifilm.servlet;

import net.ifilm.service.CacheUpdService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

public class InitialCacheServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	/**
     * 日志对象引用
     */
    private static Log log = LogFactory.getLog(InitialCacheServlet.class);

    /**
     * 缓存更新服务
     */
    private CacheUpdService cacheUpdService;

    // --------------------------------------------------------------------- method

    @Override
    public void init() throws ServletException {
        long startTime = System.currentTimeMillis();

        WebApplicationContext ctx
                = (WebApplicationContext) getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
        cacheUpdService = (CacheUpdService) ctx.getBean("cacheUpdService");

        initSystemParam();
        initStaticData();

        long endTime = System.currentTimeMillis();
        if (log.isInfoEnabled()) {
            log.info("System initialize waste time " + (endTime - startTime) + " millisSeconds");
        }
    }

    private void initSystemParam() {
        log.info("initial global system parameter list");
        cacheUpdService.updSysParamList();
    }

    private void initStaticData() {
        log.info("Initial bussiness static data.");
        cacheUpdService.updFilmType();  // 缓存电影类型
        cacheUpdService.updRegion(); // 缓存电影地区
        cacheUpdService.updSlideFilmList();  // 缓存首页幻灯电影显示区
    }
} ///:~
